// 安装  mongoose

const mongoose = require("mongoose");

// 连接数据库       协议         地址          数据库
mongoose.connect("mongodb://127.0.0.1:27017/demo");

mongoose.connection.once("open", () => {
  console.log("连接成功");
});

mongoose.connection.once("error", () => {
  console.log("连接失败");
});

mongoose.connection.once("close", () => {
  console.log("连接关闭");
});

setTimeout(() => {
  mongoose.disconnect();
}, 3000);
